<template lang="html">
  <div class="box">
    <div class="hebingdingdan" v-if="hebingdingdan">
      <h2 @click="hebing()">合并订单</h2>
    </div>
    <header-title :titlemain='title'></header-title>
    <div class="title_box">
      <ul class="title_main">
        <li v-bind:class="{ title_lsit:isActive}" v-on:click="whole()">全部</li>
        <li v-bind:class="{ title_lsit:hasError}" v-on:click="obligation()">待付款</li>
        <li v-bind:class="{ title_lsit:active}" v-on:click="delivery()">待发货</li>
        <li v-bind:class="{ title_lsit:activeClass}" v-on:click="received()">待收货</li>
        <li v-bind:class="{ title_lsit:errorClass}" v-on:click="completed()">已完成</li>
      </ul>
    </div>
    <orderdetails :goodsname="goodsxiao"></orderdetails>
    <confirm v-bind:confirmModalOptions="confirmOptions" ref="myConfirm"></confirm>
  </div>
</template>
<script>
import title from "../geren/header_title.vue";
import orderdetails from "./orderdetails.vue";
import confirm from "../../alert/confirm.vue";
export default {
  name: 'geren',
  data () {
    return {
      title:"我的订单",
      jifenorder:[],
      order:[],
      putongorder:[],
      goodsxiao:[],
      isActive: true,
      hasError:false,
      active:false,
      activeClass:false,
      errorClass:false,
      hebingdingdan:false,
      typeshuju:'全部',
      confirmOptions:{},
      message:"",
      cur_id:'',
      sign:"",
      hedingorderid:"",
      checkedNames:"" 
    }
  },
  methods:{
    shujujiazai:function(argument) {
      let cur_id = sessionStorage.getItem("cur_id"),
      sign = sessionStorage.getItem("sign"),
      boxmain = argument,
      _url = "/index.php?g=app&m=shopping&a=myorder_data_post",
      routerParams = boxmain.$route.query.id;
      let _data = {
        cur_id:cur_id,
        sign:sign
      }
      boxmain.cur_id = sessionStorage.getItem("cur_id");
      boxmain.sign = sessionStorage.getItem("sign");
      boxmain.$http.post(_url,_data).then(function(data){
          if(data.data.status== "1"){
            boxmain.jifenorder=data.data.data.jifenorder;
            boxmain.order=data.data.data.order;
            boxmain.putongorder=data.data.data.putongorder;
            boxmain.whole();
          }else {
            
          }
      },function(response){
          boxmain.$toast(response);
      });
      let _hebingurl = '/index.php?g=app&m=shopping&a=get_can_merge_order',
      _hedingdata = {
        cur_id:boxmain.cur_id,
        sign:boxmain.sign
      }
      boxmain.$http.post(_hebingurl,_hedingdata).then(function(data){
        if(data.data.status== "1"){

            for (var i = 0; i < data.data.data.can_merge_list.length; i++) {
              let str = "<div class='hebing'><p>"+data.data.data.can_merge_list[i].goods_info.show_this_title+"</p><p>"+data.data.data.can_merge_list[i].goods_info.show_this_price+"</p><p>"+data.data.data.can_merge_list[i].num+"</p><input type='checkbox' name='vehicle' value='"+data.data.data.can_merge_list[i].id+"' v-model='checkedNames' /></div>";
              boxmain.hedingorderid+=data.data.data.can_merge_list[i].id+",";
              boxmain.message+=str;
            }
        }else {
          boxmain.$toast(data.data.info);
          if(data.data.info =="登录过期，请重新登录"){
            sessionStorage.clear();
            top.location = "index.html";
          }
        }
      },function(response){
          boxmain.$toast(response);
      })
    },
    whole:function(){
      let conent = this;
      conent.isActive = true;
      conent.hasError = false;
      conent.active = false;
      conent.activeClass = false;
      conent.errorClass = false;
      conent.hebingdingdan = false;
      conent.goodsxiao.splice(0,conent.goodsxiao.length);
      for (let Key in conent.jifenorder) {
        if(conent.jifenorder[Key].length>0){
          for (var i = 0; i < conent.jifenorder[Key].length; i++) {
            conent.jifenorder[Key][i].dinfdantype = "jifen";
            conent.goodsxiao.push(conent.jifenorder[Key][i]);
          }
        }
      }
      for (let Key in conent.order) {
        if(conent.order[Key].length>0){
          for (var i = 0; i < conent.order[Key].length; i++) {
            conent.order[Key][i].dinfdantype = "cuxiao";
            conent.goodsxiao.push(conent.order[Key][i]);
          }
        }
      }
      for (let Key in conent.putongorder) {
        if(conent.putongorder[Key].length>0){
          for (var i = 0; i < conent.putongorder[Key].length; i++) {
            conent.putongorder[Key][i].dinfdantype = "putong";
            conent.goodsxiao.push(conent.putongorder[Key][i]);
          }
        }
      }
    },
    obligation:function(){
      let conent = this;
      conent.isActive = false;
      conent.hasError = true;
      conent.active = false;
      conent.activeClass = false;
      conent.errorClass = false;
      conent.typeshuju = "待付款";
      conent.hebingdingdan = false;
      conent.goodsxiao.splice(0,conent.goodsxiao.length);
      for (let Key in conent.putongorder) {
        if(Key == "unpay"){
          if(conent.putongorder[Key].length>0){
            for (var i = 0; i < conent.putongorder[Key].length; i++) {
              conent.putongorder[Key][i].dinfdantype = "putong";
              conent.goodsxiao.push(conent.putongorder[Key][i])
            }
          }
        }
      }
    },
    delivery:function(){
      let conent = this;
      conent.isActive = false;
      conent.hasError = false;
      conent.active = true;
      conent.activeClass = false;
      conent.errorClass = false;
      conent.typeshuju = "待发货";
      conent.hebingdingdan = true;
      conent.goodsxiao.splice(0,conent.goodsxiao.length);
      for (let Key in conent.jifenorder) {
        if(Key == "send_mobile_fahuo_apply"){
          if(conent.jifenorder[Key].length>0){
            for (var i = 0; i < conent.jifenorder[Key].length; i++) {
              conent.jifenorder[Key][i].dinfdantype = "jifen";
              conent.goodsxiao.push(conent.jifenorder[Key][i]);
            }
          }
        }
      }
      for (let Key in conent.order) {
        if(Key=="prize_unoption"||Key=="guess"||Key=="unprize_unoption"||Key=="prize_goods_unsend_apply"||Key=="unprize_goods_unsend_apply"||Key=="prize_goods_send_mobile_fahuo_apply"||Key=="unprize_goods_send_mobile_fahuo_apply"){
          if(conent.order[Key].length>0){
            for (var i = 0; i < conent.order[Key].length; i++) {
              conent.order[Key][i].dinfdantype = "cuxiao";
              conent.goodsxiao.push(conent.order[Key][i]);
            }
          }
        }
      }
      for (let Key in conent.putongorder) {
        if(Key == "send_mobile_fahuo_apply"){
          if(conent.putongorder[Key].length>0){
            for (var i = 0; i < conent.putongorder[Key].length; i++) {
              conent.putongorder[Key][i].dinfdantype = "putong";
              conent.goodsxiao.push(conent.putongorder[Key][i])
            }
          }
        }
      }
    },
    received:function(){
      let conent = this;
      conent.isActive = false;
      conent.hasError = false;
      conent.active = false;
      conent.activeClass = true;
      conent.errorClass = false;
      conent.typeshuju = "待收货";
      conent.hebingdingdan = false;
      conent.goodsxiao.splice(0,conent.goodsxiao.length);
      for (let Key in conent.jifenorder) {
        if(Key == "send_back_fahuo_comfirm"){
          if(conent.jifenorder[Key].length>0){
            for (var i = 0; i < conent.jifenorder[Key].length; i++) {
              conent.jifenorder[Key][i].dinfdantype = "jifen";
              conent.goodsxiao.push(conent.jifenorder[Key][i])
            }
          }
        }
      }
      for (let Key in conent.order) {
        if(Key=="prize_goods_send_back_fahuo_comfirm"||Key=="unprize_send_back_fahuo_comfirm"){
          if(conent.order[Key].length>0){
            for (var i = 0; i < conent.order[Key].length; i++) {
              conent.order[Key][i].dinfdantype = "cuxiao";
              conent.goodsxiao.push(conent.order[Key][i])
            }
          }
        }
      }
      for (let Key in conent.putongorder) {
        if(Key == "send_back_fahuo_comfirm"){
          if(conent.putongorder[Key].length>0){
            for (var i = 0; i < conent.putongorder[Key].length; i++) {
              conent.putongorder[Key][i].dinfdantype = "putong";
              conent.goodsxiao.push(conent.putongorder[Key][i])
            }
          }
        }
      }
    },
    completed:function(){
      let conent = this;
      conent.isActive = false;
      conent.hasError = false;
      conent.active = false;
      conent.activeClass = false;
      conent.errorClass = true;
      conent.typeshuju = "已完成";
      conent.hebingdingdan = false;
      conent.goodsxiao.splice(0,conent.goodsxiao.length);
      for (let Key in conent.jifenorder) {
        if(Key == "send_mobile_shouhuo_comfirm"){
          if(conent.jifenorder[Key].length>0){
            for (var i = 0; i < conent.jifenorder[Key].length; i++) {
              conent.jifenorder[Key][i].dinfdantype = "jifen";
              conent.goodsxiao.push(conent.jifenorder[Key][i])
            }
          }
        }
      }
      for (let Key in conent.order) {
        if(Key=="prize_goods_send_mobile_shouhuo_comfirm"||Key=="unprize_ungoods_send_mobile_shouhuo_comfirm"){
          if(conent.order[Key].length>0){
            for (var i = 0; i < conent.order[Key].length; i++) {
              conent.order[Key][i].dinfdantype = "cuxiao";
              conent.goodsxiao.push(conent.order[Key][i])
            }
          }
        }
      }
      for (let Key in conent.putongorder) {
        if(Key == "send_mobile_shouhuo_comfirm"){
          if(conent.putongorder[Key].length>0){
            for (var i = 0; i < conent.putongorder[Key].length; i++) {
              conent.putongorder[Key][i].dinfdantype = "putong";
              conent.goodsxiao.push(conent.putongorder[Key][i])
            }
          }
        }
      }
    },
    hebing:function(){
      let conent = this,
      _url = '/index.php?g=app&m=shopping&a=get_can_merge_order',
      _tijaoshuju = '/index.php?g=app&m=shopping&a=merge_order_post',
      _data = {
        cur_id:conent.cur_id,
        sign:conent.sign
      }

      conent.$refs.myConfirm.showModel();
      conent.confirmOptions= {
        title: "提货提示",//提示
        title_right: "",//提示
        message: conent.message,
        btnSubmitText: "提货",//确定
        btnCancelText: "取消",//取消
        btnSubmitFunction: function () {
          var rusult="";
          var check_array=document.getElementsByName("vehicle");
          for(var i=0;i<check_array.length;i++){
            if(check_array[i].checked==true){
              rusult+=parseInt(check_array[i].value)+",";
            }
          }
          window.setTimeout(function(){
            conent.$router.push({path:'/orderohebing', query:{id:rusult}})
          },1000)
        },
        btnCancelFunction: function () {
          conent.$toast("已取消");
        }
      }
    }
  },
  created:function(){
    let conent = this;
    conent.shujujiazai(conent);
  },
  components:{
    'header-title':title,
    'orderdetails':orderdetails,
    'confirm':confirm
  }
}
</script>

<style scoped lang="less">
@import '../../../assets/less/index.less';
body{
  padding: 0;
  margin: 0;
}
.box {
  .hebingdingdan{
    width: 100vw;
    height: 10vw;
    background-color: #398bfb;
    h2{
      width: 20vw;
      height: 6vw;
      line-height: 6vw; 
      font-size: 3vw;
      color: #398bfb;
      background-color: #fff;
      border-radius: 1vw;
      float: right;
      margin-right: 4vw;
      margin-top: 2vw;
    }
  }
  .title_box{
    width: 100vw;
    height: 13.3vw;
    font-size: @h1_font_size;
    .title_main{
      width: 100%;
      border-bottom: solid 1px @color8;
      border-top: solid 1px @color8;
      overflow: hidden;
      zoom:1;
      li{
        width: 20%;
        line-height: 13.33vw;
        height: 13.33vw;
        display: inline-block;
        float: left;
      }
      .title_lsit{
        border-bottom: solid 0.5vw @color;
        color: @color;
      }
    }
  }
}
</style>